package jmine.tec.report.impl.table.xls;

import jmine.tec.report.api.table.ReportCell;
import jmine.tec.report.impl.table.ReportTableBuilder;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

/**
 * Renderer de células de strings em xls
 * 
 * @author lundberg
 */
public class StringCellXLSRenderer implements ReportCellXLSRenderer {

    /**
     * {@inheritDoc}
     */
    public void render(HSSFWorkbook workbook, HSSFCell hssfCell, ReportCell cell) {
        hssfCell.setCellValue(this.getFormattedString(cell));
    }

    /**
     * {@inheritDoc}
     */
    public HSSFRichTextString getFormattedString(ReportCell cell) {
        if (cell.getValue() == null) {
            return new HSSFRichTextString("");
        } else {
            return new HSSFRichTextString(cell.getValue().toString());
        }
    }

    /**
     * {@inheritDoc}
     */
    public String getRendererType() {
        return ReportTableBuilder.TYPE_STRING;
    }
}
